﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using SpringWaterDataAccess;
using Utilities;

namespace client
{
	/// <summary>
	/// Summary description for bloggerhome.
	/// </summary>
	public partial class bloggerhome : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid DataGrid2;
	
		protected int userID = 0;

		protected void Page_Load(object sender, System.EventArgs e)
		{
			if (!Helper.IdentifyUser(Request)) 
			{
				Response.Write("你不是正确的用户!");
				Response.Redirect("bloggermain.aspx"); 
			}

			userID = System.Convert.ToUInt16(Request.QueryString["UserID"]);
			// Put user code to initialize the page here
            if (!IsPostBack) 
			{
			    ForumDataAccess da = new ForumDataAccess();

				int totalRecords = 0;
			   
				Repeater2.DataSource = da.getPosts(userID, 0,0,0,
					1, 5, out totalRecords, "blog", "", 0, "CreateDate");

			    Repeater2.DataBind();

			   Repeater1.DataSource =  da.getRepliesByUserID(userID, 1, 10, 
					out totalRecords, "blog", "", 0, "CreateDate");
				Repeater1.DataBind();
			}
		}

		public int GetTotalPosts()
		{
			int totalRecords = 0;
			ForumDataAccess da = new ForumDataAccess();
			da.getPosts(userID, 0,0,0,
				0, 0, out totalRecords, "blog", "", 0, "CreateDate");
			
			return totalRecords;
		}

		public int GetTotalPostReplies()
		{
			int totalRecords = 0;
			ForumDataAccess da = new ForumDataAccess();
			da.getRepliesByUserID(userID, 0, 0, 
				out totalRecords, "blog", "", 0, "CreateDate");

			return totalRecords;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		private void DataGrid2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}

  	    protected void Button1_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerhome.aspx?UserID=" + userID);
        }

        protected void Button2_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerinput.aspx?UserID=" + userID);

        }

        protected void Button3_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerarticles.aspx?UserID=" + userID);
        }

        protected void Button4_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggercomments.aspx?UserID=" + userID);
        }

		
	}
}
